//格式化日期函数
function onDateRenderer(e) {
    var date = new Date(e.value);
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
    var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
    var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
    var formatTime = Y + M + D + h + m + s;
    return formatTime;
}

//新增
function addZfjzbfInfo() {
    var data = {stat: 1};
    if (data) {
        showZfjzbfInfoWindow(data, 0);
    }
}

function editZfjzbfInfo() {
    var row = grid.getSelected();
    if (row) {
        $.ajax({
            url: "/user/getuser/getLoginUserDepartId",
            type: "get",
            cache: false,
            async: false,
            success: function (success) {
                if (success.code == 1) {
                    var loginUserDepartId = success.data;
                    if (row.clab == loginUserDepartId) {
                        showZfjzbfInfoWindow(row, 0);
                    } else {
                        showZfjzbfInfoWindow(row, 1);
                    }
                } else {
                    return null;
                }
            }
        })
    } else {
        alert("请至少选择一条数据！");
    }
}

function checkZfjzbfInfo() {
    var row = grid.getSelected();
    if (row) {
        showZfjzbfInfoWindow(row, 1);
    } else {
        alert("请至少选择一条数据！");
    }
}

//新增修改跳转页面
function showZfjzbfInfoWindow(row, flog) {
    commonEdit("/azbj/zfjzbf/baseinfo/view/" + flog, "政府救助帮扶信息", row, "55%", "50%", true, true, true, callback);

    function callback() {
        grid.reload();
    }
}

function delZfjzbfInfo() {
    var row = grid.getSelected();
    if (row) {
        $.ajax({
            url: "/user/getuser/getLoginUserDepartId",
            type: "get",
            cache: false,
            async: false,
            success: function (success) {
                if (success.code == 1) {
                    var loginUserDepartId = success.data;
                    if (row.clab == loginUserDepartId) {
                        commonRemove("/azbj/zfjzbf/baseinfo/delete/" + row.id, row, {_method: "delete"}, callback);

                        function callback() {
                            grid.reload();
                        }
                    } else {
                        mini.alert("非本机构添加的内容无法进行删除");
                    }
                } else {
                    return null;
                }
            }
        })
    } else {
        alert("请至少选择一条数据！");
    }
}

//帮扶类目转化
function onChangeCode(e) {
    var bflmtype = e.value;
    if (bflmtype == 1) {
        return "落实减免税政策";
    } else if (bflmtype == 2) {
        return "落实责任田";
    } else if (bflmtype == 3) {
        return "落实最低生活保障";
    } else if (bflmtype == 4) {
        return "落实特困人员供养";
    } else if (bflmtype == 5) {
        return "落实医疗救助";
    } else if (bflmtype == 6) {
        return "落实住房救助";
    } else if (bflmtype == 7) {
        return "提供就业信息";
    } else if (bflmtype == 8) {
        return "就业培训";
    } else if (bflmtype == 9) {
        return "心理疏导";
    } else if (bflmtype == 10) {
        return "组织开展教育活动";
    } else {
        return "其他";
    }
}

//批量导出
function exportZfjzbfExcelFile(e) {
    var num = grid.getData().length;
    if (num > 0) {
        top.location.href = encodeURI("/azbj/abwordresource/common/exportExcelFile?type=5");
    } else {
        mini.alert("没有数据可导出");
    }
}